package com.jw.debezuim.config.context;

import com.auth0.jwt.interfaces.DecodedJWT;
import com.jw.debezuim.common.dto.LoginUserDto;
import com.jw.debezuim.common.exception.BusinessException;

/**
 **/
public final class TC extends AbsTC {

    private static final String USER_INFO = "user_info";
    private static final String JWT = "jwt";

    public static void setUserInfo(LoginUserDto loginUserDto) {
        getMap().put(USER_INFO, loginUserDto);
    }
    public static LoginUserDto getUserInfo() {
        return (LoginUserDto) getMap().get(USER_INFO);
    }
    public static boolean isManager() {
        Integer role = getUserInfo().getRole();
        return role != null && role == 1;
    }
    public static void checkManagerAuth() {
        if (!isManager()) {
            throw new BusinessException("非管理员不可操作");
        }
    }
    public static void setJwt(DecodedJWT jwt) {
        getMap().put(JWT, jwt);
    }
    public static DecodedJWT getJwt() {
        return (DecodedJWT) getMap().get(JWT);
    }

    private TC() {
    }
}
